using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Events;

public class PlayerModel : Singleton<PlayerModel>
{
    /************数据**************/
    // 血量
    private int playerBlood;
    public int GetPlayerBlood{get{return playerBlood;}}
    // 得分
    private float playerScore;
    public float GetPlayerScore{get{return playerScore;}}

    //
    #pragma warning restore format
    //事件 用于管理函数
    private event UnityAction<PlayerModel> updateEvent;



    //2.初始化,获取数据
    public void InfoInitialize(int playerBlood, float playerScore)
    {
        this.playerBlood = playerBlood;
        this.playerScore = playerScore;
    }

    //3.更新 - 保存数据
    // 血量
    public void AddPlayerBloodUpdate()
    {
        playerBlood += 1;
        UpdateInfo();
    }
    public void ReducePlayerBloodUpdate()
    {
        playerBlood -= 1;
        UpdateInfo();
    }
    public void TakePlayerDeath()
    {
        playerBlood = 0;
        UpdateInfo();
    }
    
    // 得分
    public void PlayerScoreUpdate(float score)
    {
        playerScore += score;
        UpdateInfo();
    }

    /// <summary>
    /// 添加事件
    /// </summary>
    public void AddEventListener(UnityAction<PlayerModel> function)
    {
        updateEvent += function;
    }

    /// <summary>
    /// 移除事件
    /// </summary>
    public void RemoveEventListener(UnityAction<PlayerModel> function)
    {
        updateEvent -= function;
    }

    //4.通知更新数据
    private void UpdateInfo()
    {
        // Debug.Log("更新数据");
        updateEvent?.Invoke(this);
    }
}


// //
// 名字
// private string playerName = "PlayerData";
// public string GetPlayerName{get{return playerName;}}
//
// // 当前位置
// private Vector3 playerPosition;
// public Vector3 GetPlayerPosition{get{return playerPosition;}}
// // 关卡
// private int playerSceneIndex;
// public int GetPlayerSceneIndex{get{return playerSceneIndex;}}
// // 名字更新
//     public void PlayerNameUpdate(string name)
//     {
//         playerName = name;
//         UpdateInfo();
//     }
//     
//     
//
//     // 位置
//     public void PlayerPositionUpdate(Vector3 playerPosition)
//     {
//         playerPosition = playerPosition;
//         UpdateInfo();
//     }
//
//     //
//     public void PlayerSceneIndexUpdate(int sceneIndex)
//     {
//         playerSceneIndex = sceneIndex;
//         UpdateInfo();
//     }
//
//     /// <summary>
//     /// 保存数据
//     /// </summary>
//     private void SaveInfo()
//     {
//         PlayerData playerData = new PlayerData();
//         playerData.playerName = playerName;
//         playerData.playerBlood = playerBlood;
//         playerData.playerScore = playerScore;
//         playerData.playerRevivalPoint = playerPosition;
//         playerData.sceneIndex = playerSceneIndex;
//         SaveDataSystem.SaveByJson(playerName, playerData);
//         UpdateInfo();
//     }
